import type {Ref} from "vue"
import {ref} from "vue"
import {getCateList} from "@/api/category"
import {useRouter} from "vue-router";

type classifyListType = {
    bannerList: string;
    picUrl: string
    bannerUrl: string;
    categoryType: number;
    extra: null;
    frontDesc: string;
    frontName: string;
    frontNameIcon: null;
    iconUrl: string;
    id: string;
    imgUrl: string;
    level: string;
    name: string;
    showIndex: number;
    subCateList: [];
    superCategoryId: number;
    type: number;
    wapBannerUrl: string;
    wapExpandPicTargetUrl: null;
    categoryList: [
        {
            id: number;
            name: string;
            wapBannerUrl: string;
            superCategoryId: string;
        }
    ];
};
export function useCateList() {
    const value: Ref<string> = ref("")
    const active: Ref<number> = ref(0)
    const router = useRouter()
    const categoryL1List: Ref<Array<classifyListType>> = ref([])
    const categoryL2List: Ref<Array<classifyListType>> = ref([])
    const currentCategory: Ref<Array<classifyListType>> = ref([])
    getCateList({
        csrf_token: "40d9d966a116291c04abbd2b15ede374",
        __timestamp: 1677294268737,
        categoryId: "",
    }).then(res => {
        console.log(res);
        categoryL1List.value = res.data.data.categoryL1List
        categoryL2List.value = res.data.data.categoryL2List
        currentCategory.value = res.data.data.currentCategory.bannerList
        console.log(categoryL1List);
        console.log(categoryL2List);
        console.log(currentCategory);
    })
    const clickHandler = function (id: string) {
        getCateList({
            csrf_token: "40d9d966a116291c04abbd2b15ede374",
            __timestamp: 1677294268737,
            categoryId: id,
        }).then(res => {
            console.log(res);
            categoryL1List.value = res.data.data.categoryL1List
            categoryL2List.value = res.data.data.categoryL2List
            currentCategory.value = res.data.data.currentCategory.bannerList
            console.log(categoryL1List);
            console.log(categoryL2List);
            console.log(currentCategory);

        })
    }
    const onfocus = function(){
        router.push("/search")
    }
    return {
        value, active, categoryL1List, categoryL2List, clickHandler, currentCategory,onfocus
    }
}
